var t = require("../../requests/request.js"), e = getApp();

Page({
    data: {
        userInfo: {},
        detailList: [],
        method: "vote.topicdetail",
        pindex: 1,
        psize: 10,
        useragent: "wechat",
        t: "",
        Count: 0,
        userList: [],
        VoteId: "",
        isVote: !1,
        Note: ""
    },
    onLoad: function(t) {
        var e = t.voteid || "5b432600f5479c175c98786e";
        this.getTopicDetail(e), this.getUserList(e);
    },
    getTopicDetail: function(e) {
        var o = this, a = parseInt(new Date().getTime() / 1e3), n = wx.getStorageSync("opid");
        t.getTopicDetail(this.data.method, e, n, "wechat", this.data.pindex, this.data.psize, a, function(t) {
            var e = t.Data.VoteCount;
            t.Data.VoteDetails.map(function(t) {
                t.VoteItemPic = t.VoteItemPic.replace("{0}", "5"), t.VotePercent = parseInt(100 * t.VoteCount / e) + "%";
            }), o.setData({
                userInfo: t.UserData[0],
                detailList: t.Data.VoteDetails,
                VoteId: t.Data.VoteId,
                isVote: t.isVote,
                Note: t.Data.Note
            });
        }, function(t) {}, function(t) {});
    },
    getUserList: function(e) {
        var o = this, a = parseInt(new Date().getTime() / 1e3), n = wx.getStorageSync("opid");
        t.getUserList("vote.userlist", e, n, "wechat", this.data.pindex, this.data.psize, a, function(t) {
            t.Data.length > 0 && t.Data.map(function(t) {
                t.CreatedTime = t.CreatedTime.substring(5, 16).replace("T", " ").replace("-", ".");
            }), o.setData({
                Count: t.Count,
                userList: t.Data
            });
        }, function(t) {}, function(t) {});
    },
    userInfoHandler: function(e) {
        var o = this, a = e.detail.userInfo.nickName, n = encodeURI(e.detail.userInfo.avatarUrl), i = wx.getStorageSync("opid"), s = e.target.dataset.detailid, c = e.target.dataset.itemid, r = e.target.dataset.voteid, u = wx.getStorageSync("UserToken"), d = new Date().getTime();
        t.getUserVote("vote.uservote", r, a, n, i, "wechat", s, c, u, d, function(t) {
            wx.showToast({
                title: "投票成功",
                icon: "succes",
                duration: 1e3,
                mask: !0
            }), o.getTopicDetail(r), o.getUserList(r);
        }, function(t) {}, function(t) {});
    },
    returnBtn: function() {
        e.gotoIndex();
    },
    goAddHelp: function() {
        wx.navigateTo({
            url: "../addhelp/addhelp"
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function(t) {
        "button" === t.from ? console.log("来自页面的按钮") : console.log("来自右上角转发菜单");
        var e = "/pages/helpChose/helpChose?voteid=" + t.target.dataset.voteid;
        return console.log(e), {
            title: "朋友帮选车",
            path: e,
            imageUrl: "http://res.app.yiche.com/wechatapp/share_img.png",
            success: function(t) {
                console.log("转发成功", t);
            },
            fail: function(t) {
                console.log("转发失败", t);
            }
        };
    }
});